package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizTravelLog;
import com.ambulance.project.manager.service.IBizTravelLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆出车日志Controller
 *
 * @author zr
 * @date 2020-05-29
 */
@RestController
@RequestMapping("/manager/log")
public class BizTravelLogController extends BaseController {
    @Autowired
    private IBizTravelLogService bizTravelLogService;

    /**
     * 查询车辆出车日志列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizTravelLog bizTravelLog) {
        startPage();
        List<BizTravelLog> list = bizTravelLogService.selectBizTravelLogList(bizTravelLog);
        return getDataTable(list);
    }

    /**
     * 导出车辆出车日志列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:log:export')")
    @Log(title = "车辆出车日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizTravelLog bizTravelLog) {
        List<BizTravelLog> list = bizTravelLogService.selectBizTravelLogList(bizTravelLog);
        ExcelUtil<BizTravelLog> util = new ExcelUtil<BizTravelLog>(BizTravelLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取车辆出车日志详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizTravelLogService.selectBizTravelLogById(id));
    }

    /**
     * 新增车辆出车日志
     */
    //@PreAuthorize("@ss.hasPermi('manager:log:add')")
    @Log(title = "车辆出车日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizTravelLog bizTravelLog) {
        return toAjax(bizTravelLogService.insertBizTravelLog(bizTravelLog));
    }

    /**
     * 修改车辆出车日志
     */
    //@PreAuthorize("@ss.hasPermi('manager:log:edit')")
    @Log(title = "车辆出车日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizTravelLog bizTravelLog) {
        return toAjax(bizTravelLogService.updateBizTravelLog(bizTravelLog));
    }

    /**
     * 删除车辆出车日志
     */
    //@PreAuthorize("@ss.hasPermi('manager:log:remove')")
    @Log(title = "车辆出车日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizTravelLogService.deleteBizTravelLogByIds(ids));
    }
}
